"use server"
import React from "react";
import {getSession} from "@/lib/session";
import {AppSidebar} from "@/app/(dashboard)/home/app-sidebar";
import db from "@/lib/db";
import {redirect} from "next/navigation";

const Layout =  async ({children}:Readonly<{children:React.ReactNode}>) => {
    const session = await getSession();

    if(!session){
        return redirect("/login");
    }

    const user = await db.users.findUnique({
        where:{
            userId:session.userId
        }
    });

    if (!user) {
        return redirect("/login");
    }

    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const {password, createdAt, updatedAt, ...userInfo} = user;

    return <>
        <AppSidebar user={userInfo} >
            {children}
        </AppSidebar>
    </>
}

export default Layout;